// Padillatech.com 2007

function popup(content, closeAction){
	var cont = document.getElementById(content);
	if(arguments.length < 3)
		new Popup(cont, closeAction);
	else{
		new Popup(cont, closeAction, arguments[2]);
		}
	
	cont.style.display = "block";
}

// Determine how much the visitor had scrolled
function getScrolled(coord){
	var scrolledX, scrolledY;
	if( self.pageYOffset ) {
  		scrolledX = self.pageXOffset;
  		scrolledY = self.pageYOffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
  		scrolledX = document.documentElement.scrollLeft;
  		scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
  		scrolledX = document.body.scrollLeft;
  		scrolledY = document.body.scrollTop;
	}
	if(coord == "x")
		return scrolledX;
	else
		return scrolledY;
}

// Determine the coordinates of the center of the page
function getCenter(coord){
	var centerX, centerY;
	if( self.innerHeight ) {
  		centerX = self.innerWidth;
  		centerY = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		centerX = document.documentElement.clientWidth;
  		centerY = document.documentElement.clientHeight;
	} else if( document.body ) {
  		centerX = document.body.clientWidth;
  		centerY = document.body.clientHeight;
	}
	if(coord == "x")
		return centerX/2; 
	else
		return	centerY/2;
}

function Popup(content, closeAction){
	
	var _self = this;
	 var wrapper = document.getElementById("fadewrapper");
	_self.docBody = document.getElementsByTagName('body')[0];
	wrapper.style.opacity = 3 / 10;
	wrapper.style.filter = 'alpha(opacity=' + 3 * 10 + ')';
	if(document.getElementById("popup")){
		temp = document.getElementById("popup").firstChild;
		temp.style.display = "none";
		_self.docBody.appendChild(temp);
		//document.getElementsByTagName("html")[0].removeChild(document.getElementById("popup"));
		_self.docBody.removeChild(document.getElementById("popup"));
	}
	
	
	/*
	_self.openAction = openAction;
	_self.openAffect = openAffect;
	
	_self.closeAffect = closeAffect;
	*/
	_self.closeAction = closeAction;
	_self.content = content;
	
	var container = document.createElement('div');
	container.id='popup';
	
	if(arguments.length < 3)
		container.className = 'popup';
	else{
		container.className = arguments[2];
	}
	
	var div = document.createElement('div');
	div.className = 'header';
	
	var top = document.createElement('b');
	top.className = 'top';
	
	var b = document.createElement('b');
	b.className = 'b1';
	top.appendChild(b);
	
	b = document.createElement('b');
	b.className = 'b2';
	top.appendChild(b);
	
	b = document.createElement('b');
	b.className = 'b3';
	top.appendChild(b);
	
	b = document.createElement('b');
	b.className = 'b4';
	top.appendChild(b);
	
	div.appendChild(top);

	var boxContent = document.createElement('div');
	boxContent.className = 'popcontent';

	var myHead = document.createElement('div');
		myHead.className = 'pophead';
	
	var pic = document.createElement('img');
		pic.src = 'images/close.png';
		pic.onclick = function(){
															if(_self.closeAction) 
																_self.closeAction();
															wrapper.style.opacity = 1;
															wrapper.style.filter = 'alpha(opacity=' + 100 + ')'; 
															container.style.display = "none";
														};
		
		//a.appendChild(pic);
	
	myHead.appendChild(pic);
	boxContent.appendChild(myHead);

	boxContent.appendChild(_self.content);
	div.appendChild(boxContent);
	container.appendChild(div);
	_self.docBody.appendChild(container);
	
	container.style.opacity = 10 / 10;
	container.style.filter = 'alpha(opacity=' + 10 * 10 + ')';
	container.style.display = 'block';
	
	var centerX = Math.abs(getCenter("x") - (container.offsetWidth /2)) ;
	
	var scrolledY = getScrolled("y");
	var centerY = (getCenter("y")/3) + scrolledY;

	container.style.top = centerY+"px";	
	container.style.left = centerX+"px";
}

//Drag and Drop script - http://www.btinternet.com/~kurt.grigg/javascript

if  (document.getElementById){

(function(){

//Stop Opera selecting anything whilst dragging.
if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx;

function move(e){
if (!e) e = window.event;
 if (dragok){
	
  d.style.left = dx + e.clientX - x + "px";
  d.style.top  = dy + e.clientY - y + "px";
  return false;
 }
}

function down(e){
	if (!e) e = window.event;
	var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
	if (temp.tagName != "HTML"|"BODY" && temp.className != "pophead"){
		temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
	}
	if (temp.className == "pophead"){
		temp = temp.parentNode.parentNode.parentNode;
		//temp.style.position = "relative";
		if (window.opera){
			document.getElementById("Q").focus();
		}
		dragok = true;
		//temp.style.zIndex = 1;
		d = temp;
		dx = parseInt(temp.style.left+0);
		dy = parseInt(temp.style.top+0);
		if(dx == 0)
			dx = 340;
		if(dy == 0)
			dy = 50;
		
		x = e.clientX;
		y = e.clientY;
		
		document.onmousemove = move;
		return false;
	}
}


function up(){
	dragok = false;
	document.onmousemove = null;
}

document.onmousedown = down;
document.onmouseup = up;

})();
}